<?php
header("Content-type: text/html; charset=utf-8");
session_start();
if(!(isset($_SESSION['loggedUsername']) and $_SESSION['loggedUsername'] != "")){
    echo "<script>alert('只有登录后才能投票！');location.href='login.php';</script>";
    exit;
}
$id = $_GET['id'];
if(($id == '') or !is_numeric($id)){
    //说明参数有误，给出提示，返回
    echo "<script>alert('参数错误！');history.back();</script>";
    exit;
}
include_once "conn.php";
$sql = "update carinfo set currentNum = currentNum + 1 where id = $id";
$result = mysqli_query($conn,$sql);
if($result){
    echo "<script>alert('投票成功！');location.href='index.php';</script>";
}
else{
    echo "<script>alert('投票失败！');history.back();</script>";
}